package com.ks.winterwarmimage.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ks.winterwarmimage.R;

import java.util.List;

public class DeviceAdapter extends BaseAdapter {
   private List<DevItem> devItemList;
   private Context mContext;
   public DeviceAdapter(Context context, List<DevItem> devItemList) {
      this.mContext = context;
      this.devItemList = devItemList;
   }
   @Override
   public int getCount() {
      return devItemList != null ? devItemList.size() : 0;
   }

   @Override
   public DevItem getItem(int position) {
      return devItemList != null ?  devItemList.get(position) : null;
   }

   @Override
   public long getItemId(int i) {
      return i;
   }

   @Override
   public View getView(int position, View view, ViewGroup viewGroup) {
      ViewHolder viewHolder;
      if(view==null){
         view=View.inflate(mContext, R.layout.query_dev_view,null);
         viewHolder=new ViewHolder(view);
         view.setTag(viewHolder);
      }else{
         viewHolder=(ViewHolder)view.getTag();
      }
      if(devItemList!=null){
         DevItem item=devItemList.get(position);
         viewHolder.setDevice(item);
      }
      return view;
   }

   class ViewHolder{
      TextView textDevName,textDevBssid;
      public ViewHolder(View view) {
         textDevName=view.findViewById(R.id.text_dev_name);
         textDevBssid=view.findViewById(R.id.text_dev_bssid);
      }
      public void setDevice(DevItem item) {
         textDevName.setText(item.devName);
         textDevBssid.setText(item.deviceId);
      }
   }
}
